package com.kmzx.one.project.service.impl;

import com.kmzx.one.common.exceptions.ParameterNullException;
import com.kmzx.one.project.entity.UserOrder;
import com.kmzx.one.project.entity.UserOrderSubs;
import com.kmzx.one.project.entity.Warehouse;
import com.kmzx.one.project.entity.WarehouseDetail;
import com.kmzx.one.project.net.CartParam;
import com.kmzx.one.project.net.OnceParam;
import com.kmzx.one.project.net.OrderParam;
import com.kmzx.one.project.others.dto.UserOrderFinalInfo;
import com.kmzx.one.project.service.UserBillService;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public class UserBillServiceImpl implements UserBillService {

    public UserOrderFinalInfo doGenOrder(OrderParam orderParam) {
        int i = orderParam.checkWhich();
        if (i == 0) {
            throw new ParameterNullException("参数为空,不支持交易");
        }
        if (i == 1) {
            UserOrderFinalInfo cart = cartToDealwith(orderParam.getCart());
            return cart;
        }
        if (i == 2) {
            UserOrderFinalInfo once = instanceToDealwith(orderParam.getOnce());
            return once;
        }
        return null;
    }


    public UserOrderFinalInfo cartToDealwith(CartParam cartParam) {

        return null;
    }

    public UserOrderFinalInfo instanceToDealwith(OnceParam onceParam) {

        return null;
    }

    // 处理库存
    @Transactional(rollbackFor = Throwable.class)
    public void handleToWarehouse(List<Warehouse> warehouses, List<WarehouseDetail> warehouseDetails) {

    }

    // 处理订单支付
    @Transactional(rollbackFor = Throwable.class)
    public void handleToPay(UserOrder userOrder, List<UserOrderSubs> orderSubs) {

    }

}
